/* 导航守卫-控制页面访问权限 */
import router from '@/router/index.js'
import store from '@/store/index'

router.beforeEach(async(to, from, next) => {
  if (store.state.user.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    // 判断此时候用户跳转是否是登录页面，是就放行
    const whiteArr = ['/login', '/404', '/test', '/register']
    if (whiteArr.indexOf(to.path) !== -1) {
      next()
    } else {
      next('/login')
    }
  }
})
